package cn.zzuli.springcloud.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Date: 2020/12/25 20:29
 * @Author: 绯色下午茶
 * @Description:
 */
@Slf4j
@RestController
@RequestMapping("/sentinel")
public class FlowLimitController {
    @GetMapping("/testA")
    public String testA() {
//        try {
//            TimeUnit.MILLISECONDS.sleep(800);
//
//        }catch (Exception e){
//            e.printStackTrace();
//        }
        return "****************testA";
    }

    @GetMapping("/testB")
    public String testB() {
//        log.info("哈哈哈哈");
        return "****************testB";
    }

    @GetMapping("/testC")
    public String testC() {
//        try {
//            TimeUnit.SECONDS.sleep(1);
//
//        }catch (Exception e){
//            e.printStackTrace();
//        }

//        int a = 10/0;
        log.info("testC");
        return "****************测试异常比例";
    }

    @GetMapping("/testHotKey")
    @SentinelResource(value = "testHotKey", blockHandler = "deal_testHotKey",fallback = "deal_testHotKey")
    public String testHotKey(@RequestParam(value = "p1", required = false) String p1,
                             @RequestParam(value = "p1", required = false) String p2) {
        int a= 10/0;
        return "****************testHotKey";
    }

    public String deal_testHotKey(@RequestParam(value = "p1", required = false) String p1,
                                  @RequestParam(value = "p1", required = false) String p2,
                                  BlockException expection) {
        return "****************deal_testHotKey";
    }

}
